"""
演示多继承
"""


class People:
    age = 0
    name = ""
    __idcard = ""  # 私有的属性，只能在本类访问

    def __init__(self, name, age, idcard) -> None:
        self.name = name
        self.age = age
        self.__idcard = idcard
        super().__init__()

    def print_stu_info(self):
        print(f'父类(People)方法(print_stu_info)：name = {self.name} age={self.age}')

    # 公共方法
    def print_stu_name(self):
        print(f'父类(People)方法(print_stu_name)：name = {self.name} ')


class Student:
    __stuno = ""

    # 构造方法1
    def __init__(self, stuno):
        self.__stuno = stuno

    def print_stu_info(self):
        print(f'父类(Student)方法(print_stu_info) 学生信息：name = {self.name} age={self.age} stuno={self.__stuno} ')


# 多继承，运算符重载演示
class Xiaoming(Student, People):  # 多继承

    def __init__(self, stuno, name, age, idcard):
        Student.__init__(self,stuno)  # 调用父类Student的构造方法
        People.__init__(self,name, age, idcard)  # 调用父类People的构造方法

    #专有方法进行重载，对象实例被打印时被调用
    def __str__(self) -> str:
        return f'name = {self.name} age={self.age}'

    #专有方法进行重载，对象相加会被调用
    def __add__(self, other):
        return self.age+other.age


if __name__ == '__main__':
    # 创建对象实例
    stu = Xiaoming(1, "tom", 20, "121321313")
    # 直接访问公共属性，无法访问私有属性
    print(f'name = {stu.name} age = {stu.age}')
    # 2个父类有一样的方法，则调用第一个继承的父类即Student的方法
    stu.print_stu_info()
    # 调用父类方法
    stu.print_stu_name()
    #由于覆盖了专有方法,输出对象会调用xiaoming的__str__方法
    print(stu)

    stu1 = Xiaoming(2, "tom", 22, "121321313")
    # 由于覆盖了专有方法,相加会调用__add__方法
    print(stu+stu1)
